package com.zzzzzz.account.signin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.zzzzzz.account.user.UserBase;
import com.zzzzzz.account.user.UserDao;

public class CurrentUserInterceptor extends HandlerInterceptorAdapter {

	@Resource
	private OnlineService onlineService;
	@Resource
	private UserDao userDao;
	
	@Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
		try {
			UserBase userBase = userDao.findUserBaseById(onlineService.findUserId());
	        request.setAttribute("currentUser", userBase);
		} catch (NoSuchOnlineUserException e) {
			request.setAttribute("currentUser", null);
//			e.printStackTrace();
		}
    }

}
